package com.cy1;

import java.util.Arrays;
import java.util.Comparator;

/**
 * String类方法的使用
 *
 * @author CY
 * @date 2022/08/11 22:49
 **/
class Student {
    private String name;
    private int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}

public class Test implements Comparator {
    public static void main(String[] args) {
        //字符黄对象的三种常用构造
//        String s = "abc";
//        String s1 = new String("aBc");
//        String s2 = new String(new char[]{'a', 'b', 'c', 'd'});
////        System.out.println(s);
////        System.out.println(s1);
////        System.out.println(s2);
//
//        //字符串的比较equals方法和compare的使用
//        System.out.println(s1.equals(s2));
//        System.out.println(s1.compareTo(s2));
//        Test test = new Test();
//        System.out.println(test.compare(s1, s2));
//
//        //忽略大小写的字符串比较
//        System.out.println(s.compareToIgnoreCase(s1));
//
//        //获得索引出的字符
//        for (int i = 0; i < s.length(); i++) {
//            char c = s.charAt(i);
//            System.out.println(c);
//        }
//
//        //查找字符串或者字符
//        String str = "abababcabcd";
//        System.out.println(str.indexOf("b",6));
//        System.out.println(str.indexOf("abc",5));
//
//        System.out.println(str.lastIndexOf("abcd", str.length()-1));
//
//        //数字和字符串的转换
//        System.out.println(String.valueOf(12.31));
//        System.out.println(String.valueOf(true));
//        System.out.println(String.valueOf(new Student("chenyong",21)));
//
//        System.out.println(Double.valueOf("458"));
//
//        //字符串大小写转换
//        String s3="Hello陈";
//        System.out.println(s3.toUpperCase());
//        System.out.println(s3.toLowerCase());
//        System.out.println(Arrays.toString(s3.toCharArray()));
//
//        //格式化字符串
//        System.out.println(String.format("%d-%d-%d",2022,8,12));
//
//        //字符串替换
//        System.out.println(s3.replace('l', '帅'));
//        System.out.println(s3.replace("ll", "我是帅哥！"));
//        System.out.println(s3.replaceAll("ll", "我是帅哥！"));
//
//        //字符串拆分
//        String s4 = "chen.yong\\hello";
//        System.out.println(s4);
//        String[] split = s4.split(".");
//        for (String s5 : split) {
//            System.out.println(s5);
//        }
////        s4.split("\\\\");
        String s = "abc";
        String s1 = new String(new char[]{'a', 'b', 'c'});
        s1 = s1.intern();
        System.out.println(s == s1);


    }

    int firstUniqChar(String s) {
        char[] chars = s.toCharArray();
        int[] ints = new int[26];
        Arrays.setAll(ints, i -> (i - 97));
        for (int i = 0; i < chars.length; i++) {
            ints[chars[i]]++;
        }
        for (int i = 0; i < ints.length; i++) {
            if (ints[i] == 1) {
                char ch = (char) i;
                return i += 97;

            }
        }
        return -1;

    }
    public int countSegments(String s) {
        if(s.equals(" ")){
            return 0;
        }
        String[] arr=s.split(" ");
        return arr.length;

    }
//    public boolean wordPattern(String pattern, String s) {
//        char[] arr = pattern.toCharArray();
//        String[] arr1=s.split(" ");
//
//
//    }

    @Override
    public int compare(Object o1, Object o2) {
        String s = (String) o1;
        String s2 = (String) o2;
        return s.compareTo(s2);
    }
}
